﻿@model EmailSender.Models.SendEmailModel
@using EmailSender.Models
@using Kendo.Mvc.UI
@using Mn.Framework.Web.Mvc
@{
    ViewBag.Title = "ارسال ایمیل";      
}

<div class="@(string.IsNullOrEmpty(Model.ResultMessage) ? " " : "alert alert-warning col-sm-11")">@Model.ResultMessage</div>
@using (Html.BeginForm("Index", "SendEmail", FormMethod.Post, new { @class = "form-horizontal" }))
{
    int i = 0;
    @Html.ValidationSummary(true)

    @Html.Hidden("skipCount", null, new { value = Model.SkipCount })
    @Html.Hidden("EmailAddress", null, new { value = "", id = "EmailAddress" })

    <div class="form-group">
        <label class="col-sm-2 control-label" for="Category">انتخاب دسته بندی</label>
        <div class="col-sm-9">
            @Html.DropDownListFor(d => d.CategoryId, (ViewBag.Categories as List<CategoryModel>)
                .Select(s => new SelectListItem { Text = s.CatTitle, Value = s.ID.ToString() }), new { @class = "form-control" })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label" for="SmtpServer">انتخاب سرور</label>
        <div class="col-sm-9">
            @Html.DropDownListFor(d => d.SmtpServerId, (ViewBag.SmtpServers as List<SmtpServerModel>)
                .Select(s => new SelectListItem { Text = s.ServerName, Value = s.ID.ToString() }), new { @class = "form-control" })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label" for="SmtpCredential">انتخاب حساب کاربری</label>
        <div class="col-sm-9">
            @Html.DropDownListFor(d => d.SmtpCredentialId, (ViewBag.SmtpCredentials as List<SmtpCredentialModel>)
                .Select(s => new SelectListItem { Text = s.Title, Value = s.ID.ToString() }), new { @class = "form-control" })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label" for="SmtpCredential">موضوع ایمیل</label>
        <div class="col-sm-9">
            @Html.TextBox("Subject", "", new { @class = "form-control" })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label" for="editor">محتوای ایمیل</label>
        <div class="col-sm-9">
            @(Html.Kendo().Editor()
                  .Name("Body")
                  .Tools(tools => tools
          .Clear()
          .Bold().Italic().Underline().Strikethrough()
          .JustifyLeft().JustifyCenter().JustifyRight().JustifyFull()
          .InsertUnorderedList().InsertOrderedList()
          .Outdent().Indent()
          .CreateLink().Unlink()
          .InsertImage()
          .SubScript()
          .SuperScript()
          .TableEditing()
          .ViewHtml()
          .Formatting()
          .FontName()
          .FontSize()
          .FontColor().BackColor()
      ).Encode(false)
                  .HtmlAttributes(new { style = "width: 700px;height:480px" })
                  .Value(@<text>
            <div style="text-align: right">
                ...
            </div>
            </text>))
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label" for="EmailAddressGrid">
            لیست ایمیل ها                   
        </label>
        <div class="col-sm-9 k-rtl">
            @(Html.Mn().MnGrid<EmailAddressModel>("EmailAddress", true)
            .Selectable(selection => selection.Mode(GridSelectionMode.Multiple).Type(GridSelectionType.Row))
            .Events(e => e.Change("onChange")))
        </div>
    </div>   
    <div class="checkbox" style="width: 120px">
        <label>
            <input type="checkbox" id="chkAutoSend" value="yes" />
            ارسال اتوماتیک
        </label>
    </div>

    <div class="form-group">
        <div class="col-sm-8 k-rtl">
            <div id="dAlert" class="alert alert-warning"></div>
        </div>
        <div class="col-xs-offset-1 col-sm-3 k-rtl">
            <input type="button" value="ارسال ایمیل" onclick="sendAutoMail()" class="btn btn-success" />
        </div>        
    </div>
}

@section Scripts {
    <script src="@Url.Content("~/Scripts/sendEmail.js")" ></script>

}
